<%@page import="java.rmi.RemoteException"%>
<%@page import="java.sql.SQLException"%>
<%@page import="exception.NotLoggedInException"%>
<%@page import="java.rmi.Naming"%>
<%@page import="clientData.MemberDataInt"%>
<%@page import="java.util.LinkedList"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>

<%@ include file="serverConnection.jsp" %>
	<%
		String prefix = request.getParameter("prefix");

		//String userName = "nir123";
		String userName=(String) session.getAttribute("userName");
		String password=(String) session.getAttribute("password");
		if((userName==null)||(password==null)){
			response.sendRedirect("loggin.jsp");
			response.flushBuffer();
			return;
		}


		LinkedList<MemberDataInt> friends = null;
		LinkedList<MemberDataInt> currentFriends = null;
		try{
			friends = forum.lookForForumUsers(userName, password, prefix);
			currentFriends = forum.getUserFriends(userName,password);
		}
		catch(NotLoggedInException t)
		{
			response.sendRedirect("loggin.jsp");
			response.flushBuffer();
			return;
		}
			catch(SQLException s){
				   
				   
				   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
					"SQL server is down");
				
					response.flushBuffer();
					return;
				   
				   
			   }
			   catch(RemoteException u){
				   
				   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
					"forum server is down");
				
					response.flushBuffer();
					return;
			   }
		
		
	%>
	<select id="usersList" name="usersList" size="10">
		<%
			for(MemberDataInt friend : friends){	
				if (!friend.getUserName().equals(userName)){
					boolean flag = true;
					for(MemberDataInt currentFriend : currentFriends){			
						if (friend.getUserName().equals(currentFriend.getUserName())){
							flag = false;
							break;		
						}
					}
					if(flag){
						%><option value="<%= friend.getUserName()%>"><%= friend.getUserName()%></option><%
					}
				}
			}
		%>
	</select>


